package com.gxa.modules.app.outpatient.onlinepay.service.impl;


import com.gxa.common.utils.Result;
import com.gxa.modules.app.outpatient.onlinepay.dto.PayDetail;
import com.gxa.modules.app.outpatient.onlinepay.mapper.OnlinePayMapper;
import com.gxa.modules.app.outpatient.onlinepay.service.OnlinePayService;
import com.gxa.modules.app.outpatient.onlinepay.service.RechargeOrderInfoAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName PatientServiceImpl
 * @Description
 * @Author Mr.YUAN
 * @Date 2022/11/12 11:27
 */
@Service
public class OnlinePayserviceImpl implements OnlinePayService {

    @Autowired
    private OnlinePayMapper onlinePayMapper;

    @Autowired
    private RechargeOrderInfoAppService rechargeOrderInfoAppService;

    @Override
    public Result onlinePay(double rechargeMoney, Integer id, Integer userId, String payPwd) {
        String paypassword = onlinePayMapper.getByUserId(userId);
        if (payPwd.equals(paypassword)){

            double cardBalance = onlinePayMapper.getMondyById(id);
            //往订单里面加数据
            rechargeOrderInfoAppService.addOrderDetail(rechargeMoney,cardBalance,id);
            //更改就诊人就诊卡的余额
            double totalMoney = rechargeMoney + cardBalance;
            onlinePayMapper.updateMoney(totalMoney,id);
            return new Result().ok();
        }else {
            return new Result().error("支付失败");
        }


    }

    @Override
    public List<PayDetail> queryDetail(Integer id,String startTime,String endTime) {
        List<PayDetail> payDetails = onlinePayMapper.queryAllById(id,startTime,endTime);
        return payDetails;
    }
}